package com.yike.user.service.impl;

import com.yike.user.entity.UserFile;
import com.yike.user.mapper.UserFileMapper;
import com.yike.user.service.UserFileService;
import com.yike.user.param.UserFilePageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 用户文件表 服务实现类
 *
 * @author Sakura
 * @since 2024-08-30
 */
@Slf4j
@Service
public class UserFileServiceImpl extends BaseServiceImpl<UserFileMapper, UserFile> implements UserFileService {

    @Autowired
    private UserFileMapper userFileMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveUserFile(UserFile userFile) throws Exception {
        return super.save(userFile);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateUserFile(UserFile userFile) throws Exception {
        return super.updateById(userFile);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteUserFile(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<UserFile> getUserFilePageList(UserFilePageParam userFilePageParam) throws Exception {
        Page<UserFile> page = new PageInfo<>(userFilePageParam, OrderItem.desc(getLambdaColumn(UserFile::getCreateTime)));
        LambdaQueryWrapper<UserFile> wrapper = new LambdaQueryWrapper<>();
        IPage<UserFile> iPage = userFileMapper.selectPage(page, wrapper);
        return new Paging<UserFile>(iPage);
    }

}
